/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.mobbuzz.renderer;

import com.sun.lwuit.Component;
import com.sun.lwuit.Container;
import com.sun.lwuit.Font;
import com.sun.lwuit.Label;
import com.sun.lwuit.List;
import com.sun.lwuit.layouts.BorderLayout;
import com.sun.lwuit.layouts.BoxLayout;
import com.sun.lwuit.list.ListCellRenderer;
import edu.mobbuzz.bean.Contact;

/**
 *
 * @author penyihir kecil
 */
public class ContactRenderer extends Container implements ListCellRenderer {
    private Label nameLbl = new Label("");
    private Label idLbl = new Label("");
    private Label focus = new Label("");
    
    public ContactRenderer(){
        setLayout(new BorderLayout());
        Container cnt = new Container(new BoxLayout(BoxLayout.Y_AXIS));
        nameLbl.getStyle().setBgTransparency(0);  
        nameLbl.getStyle().setFont(Font.createSystemFont(Font.FACE_PROPORTIONAL, Font.STYLE_BOLD, Font.SIZE_SMALL));
        idLbl.getStyle().setBgTransparency(0);

        cnt.addComponent(nameLbl);
        cnt.addComponent(idLbl);

        addComponent(BorderLayout.CENTER, cnt);
        focus.getStyle().setBgTransparency(100);
        focus.getStyle().setBgColor(0xCCCCCC);
    }
    public Component getListCellRendererComponent(List list, Object value, int index, boolean isSelected) {
       
        Contact contact = (Contact) value;
        nameLbl.setText(contact.getName());
        idLbl.setText(contact.getId());
        if(contact.getSex()==0){
            nameLbl.getStyle().setFgColor(0x49BBF9);
        }else if(contact.getSex()==1){
            nameLbl.getStyle().setFgColor(0xF59FBC);
        }else{
            nameLbl.getStyle().setFgColor(0xFFFFFF);
        }
        return this;
    }

    public Component getListFocusComponent(List list) {
        return focus;
    }

}
